
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package itm.bo.login;

//~--- non-JDK imports --------------------------------------------------------
import itm.conexion.SQLServerConection;

import itm.dao.login.LoginDAO;

import itm.exception.DAOException;
import itm.exception.LoginException;
import itm.vo.login.LoginVO;

//~--- JDK imports ------------------------------------------------------------

import itm.vo.login.RolVO;
import java.sql.Connection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrador
 */
public class LoginBO {

    LoginDAO loginDAO = null;
    SQLServerConection conexion = new SQLServerConection();
    Connection dbConexion;
    LoginVO loginVO;

    @SuppressWarnings("empty-statement")
    public LoginVO consultarUsuario(String nombreUsuario, String claveUsuario) throws Exception {
        loginVO = new LoginVO();
        ;

        try {
            //  dbConexion = conexion.openConnection();
            SQLServerConection c = new SQLServerConection();
            dbConexion = c.openConnection();

            loginDAO = new LoginDAO(dbConexion);
            loginVO = loginDAO.consultarUsuario(nombreUsuario, claveUsuario);
        } catch (Exception ex) {
            ex.getStackTrace();
        } finally {
            conexion.closeConnection(dbConexion);
        }

        return loginVO;
    }

    public List<RolVO> ObtenerPermisosRol(long idRol) throws LoginException {
        try {
            SQLServerConection c = new SQLServerConection();
            dbConexion = c.openConnection();
            loginDAO = new LoginDAO(dbConexion);
            return loginDAO.ObtenerPermisosRol(idRol);
        } catch (DAOException ex) {
            Logger.getLogger(LoginBO.class.getName()).log(Level.SEVERE, null, ex);
            throw new LoginException("Error: LoginBO:ObtenerPermisosRol", ex);
        }
    }

    public List<RolVO> listarRoles() throws LoginException {
        try {
            SQLServerConection c = new SQLServerConection();
            dbConexion = c.openConnection();
            loginDAO = new LoginDAO(dbConexion);
            return loginDAO.listarRoles();
        } catch (DAOException ex) {
            Logger.getLogger(LoginBO.class.getName()).log(Level.SEVERE, null, ex);
            throw new LoginException("Error: LoginBO:listarRoles", ex);
        }
    }

    public String personaRolExsite(long idPersona, long idRol)throws LoginException{
        try {
            SQLServerConection c = new SQLServerConection();
            dbConexion = c.openConnection();
            loginDAO = new LoginDAO(dbConexion);
            return loginDAO.personaRolExsite(idPersona, idRol);
        } catch (DAOException ex) {
            Logger.getLogger(LoginBO.class.getName()).log(Level.SEVERE, null, ex);
            throw new LoginException("Error: LoginBO:personaRolExsite", ex);
        }
    }
}
